const http = require("http");
const url = require("url");
const qs = require("querystring");
// 创建一个对应的服务器
const server = http.createServer((rqs, res) => {
  // 1.参数一: query类型参数
  const urlStr = rqs.url;
  const queryString = url.parse(urlStr).query;

  /* const urlInfo = urlStr.split("?")[1].split("&");
  const obj = {};
  urlInfo.forEach((item) => {
    const r = item.split("=");
    obj[r[0]] = r[1];
  }); */

  const urlInfo = qs.parse(queryString);
  //   const urlInfo = new URLSearchParams(queryString);
  console.log(urlInfo);
  res.end("Hello World");
});
// 开启一个服务器端口 1024 - 66535
server.listen("8000", () => {
  console.log("服务器开启成功");
});
